home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1828 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: ifstream slower than fread()?
  5. Date: 13 Jan 1996 04:10:53 GMT
  6. Organization: Pipeline USA
  7. Message-ID: <4d7bcd$4l6@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 12, 1996 20:00:31 in article <ifstream slower than fread()?>,
  15. 'jritzau@aol.com (JRitzau)' wrote: 
  16.  
  17.  
  18. >Hello! 
  19. >I was thinking iostreams of C++ are the best way to read 
  20. >and write binary files. But after testing I must see, that 
  21. >to copy a file with 'old' C-functions fwrite()/fread() do 
  22. >the job in just about half the time it was done using 
  23. >ifstream.read()/ofstream.write()?! 
  24. The iostream vs stdio speed issue was just discussed in the 
  25. last couple of days.  Read the last three days' posts for more 
  26. info.  Also, the FAQ (questions circa 100) deal with this topic. 
  27.  
  28. IMO, this speed difference is mostly due to your old compiler 
  29. system.  C stdio has been around a long time and has been 
  30. optimized while at the time BC3.0 was developed, iostreams 
  31. were still in their infancy.   
  32.  
  33. I don't see a whole lot of apparent speed difference between 
  34. the two, but then again, I typically don't use iostreams 
  35. for binary files.  I'd copy the file by getting its size, allocate 
  36. a buffer, and do one each fread()/fwrite().  Now, that's fast. 
  37. (Don't ask -- I've provided for files too big for this treatment). 
  38.  
  39. >Next problem: I've read that I must call the function  
  40. >ios::sync_with_stdio() if one program uses printf() AND cout. 
  41. Only if you want the text to appear at the output device in the 
  42. same sequence as your code's output. 
  43.  
  44. >Is there also a need for this synchronisation if I use  
  45. >fread()/fwrite() (no printf())  AND cin/cout in the same 
  46. >program? 
  47.  
  48. No.  (Just don't redirect cin or cout to the same file you 
  49. are are doing fread/fwrite. :-)) 
  50.  
  51. -- 
  52.  
  53. Pete
  54.